package com.fognl.core.net.handler;

/** A request made to the NetworkHandler. */
public interface Request
{
	/** Default timeout is infinite. */
	long TIMEOUT_INFINITE = -1;
	
	/** Return the RequestHandle associated with this request. */
	RequestHandle getHandle();
	/** Set the handle for this request. */
	Request setHandle(RequestHandle handle);
	
	/** Return the timeout period for this request. */
	long getTimeout();
	/** Set the timeout period for this request. */
	Request setTimeout(long value);
	
	/** Return the worker for this request. */
	Worker getWorker();
	
	/** A worker associated with this request. */
	static interface Worker
	{
		/** Does the work of fulfilling the request. An example would be reading data from a URL connection,
		 * reading from a file, database, etc.
		 */
		void work(Request.Worker.Listener listener) throws WorkerException;
		
		/** Return the data that resulted from the <code>work()</code> operation. */
		Object getData();
		
		static interface Listener 
		{
			void onData(Object data);
			boolean okToContinue(Worker worker);
		}
	}
}
